package com.springboot.original.common.utils;

import cn.hutool.core.util.StrUtil;

public class GennerSwagger {

    public static void main(String[] args) {

        String clip = "public String truncatecassandra() {";
        clip = clip.trim();
        if ((clip.contains("public")) && (clip.contains("(")) && (!clip.contains("}"))) {
            String methodName = StrUtil.subBefore(clip, "(", false).trim();
            methodName = StrUtil.subAfter(methodName, " ", true).trim();
            if (methodName.contains("(")) {
                methodName = StrUtil.subBefore(methodName, "(", false);
            }
            methodName = methodName.trim();

            String canShus = StrUtil.subBetween(clip, "(", ")");
            System.out.println(canShus);

            String str = "@ApiOperation(value = \"\",notes = \"\")\n";
            if (canShus.length() > 6) {
                str = str + "@ApiImplicitParams({\n";
                if (canShus.contains(",")) {
                    String[] canShu = canShus.split(",");
                    for (int i = 0; i < canShu.length; i++) {
                        canShu[i] = canShu[i].trim();
                        str = str + "@ApiImplicitParam(value = \"\", required = true,name = \"" + canShu[i].split(" ")[1] + "\", dataType = \"" + canShu[i].split(" ")[0] + "\")";
                        if (i != canShu.length - 1) {
                            str = str + ",";
                        }
                        str = str + "\n";
                    }
                } else {
                    canShus = canShus.trim();
                    str = str + " @ApiImplicitParam(value = \"\", required = true,name = \"" + canShus.split(" ")[1] + "\", dataType = \"" + canShus.split(" ")[0] + "\")\n";
                }
                str = str + "})\n";
            }
            str = str + "@PostMapping(\"/" + methodName + "\")";

            System.out.println(str);

        }
    }

}
